export const translationHeaderMap = {
  附加费名称: "surcharge_name",
  "费用类型（必填）": "fee_type",
  "物流渠道（必填）": "channel_ids",
  "币种（必填）": "currency",
  备注信息: "remark",
};
export const translationMap = {
  到达国家: "destination_country",
  邮编区域: "zip_code_ids",
  "区间下限（必填）": "rule_min_value",
  "指标（必填）": "rule_type",
  "区间上限（必填）": "rule_max_value",
  "附加费计算方式（必填）": "surcharge_calc_type",
  附加费金额: "surcharge",
  是否预估住宅发地址费: "is_pre_hone_fee",
  住宅费金额: "pre_hone_fee",
  "是否计算燃油附加费（必填）": "is_calc_fuel",
  旺季附加费是否计算燃油费: "hs_is_calc_fuel",
  旺季附加费: "hs_surcharge",
};
// 转化函数
export function translateObject(obj, translationMap) {
  const translatedObject = {};
  for (const [originalKey, translatedKey] of Object.entries(translationMap)) {
    const originalValue = obj[originalKey];
    translatedObject[translatedKey] = originalValue;
  }
  return translatedObject;
}

export function splitChannelNames(inputString) {
  if (!inputString) {
    return [];
  }
  const regex = /,|，|\n/g;
  const resultArray = inputString?.split(regex);
  const filteredArray = resultArray?.filter((item) => item?.trim() !== "");
  return filteredArray;
}

/**
 * 构造映射对象
 * @param {Array} list - 原始数组
 * @param {string} keyField - 作为对象键的字段名
 * @param {string} valueField - 作为对象值的字段名
 * @returns {Object} - 映射后的对象
 */
export function createMapping(list, keyField, valueField) {
  return (list || []).reduce((map, item) => {
    if (item[keyField] !== undefined && item[valueField] !== undefined) {
      map[item[keyField]] = item[valueField];
    }
    return map;
  }, {});
}
